/*
 * Copyright (c) 2012, Asiainfo-Linkage. All rights reserved.
 * Asiainfo-Linkage PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package edu.w106.platform.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * <p><b>标题：</b>PropertiesUtil.</p>
 *
 * <p><b>描述：配置文件的读取.</b></p>
 *
 * <p><b>版权：</b>Copyright (c) 2012 亚信联创</p>
 *
 * <p><b>工程：</b>com.w106.util</p>
 *
 * @author w106
 *
 * @version 1.0.0
 *
 * @since 2012-1-11 下午4:47:08
 */
public final class PropertiesUtil {

    private final String confFileName;

    public PropertiesUtil(String confName) {
        confFileName = confName;
    }

    public Map<String, String> read() throws IOException {
        String prefix = System.getProperty("config.dir");
        File f;
        if (prefix == null || "".equals(prefix.trim())) {
            f = new File(confFileName);
        } else {
            f = new File(prefix, confFileName);
        }
        Properties ps = new Properties();

        ps.load(new FileInputStream(f));

        Map<String, String> result = new HashMap<String, String>();
        for (Object key : ps.keySet()) {
            String skey = (String) key;
            result.put(skey, ps.getProperty(skey));
        }
        return result;

    }
}
